<template>
  <div class="status">
    <title-main title="活跃党员情况"></title-main>
    <div class="bottom">
      <div class="barEchart" ref="barEchart"></div>
      <div class="legend">
        <div class="box" v-for="(item, index) in dataList" :key="index">
          <i class="icon">{{ index + 1 }}</i>
          <span class="label">{{ item.label }}</span>
          <span class="value"
            >{{ item.value }}
            <i class="unit">次</i>
          </span>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { ref, inject, onMounted } from 'vue'
const echarts = inject('echarts')
let barEchart = ref(null)
let myEchart = null
let colorList = [
  ['rgba(29, 241, 249, 0)', 'rgba(29, 241, 249, 1)'],
  ['rgba(29, 241, 249, 0)', 'rgba(29, 241, 249, 1)'],
  ['rgba(255, 209, 48, 0)', 'rgba(255, 209, 48, 1)'],
  ['rgba(255, 209, 48, 0)', 'rgba(255, 209, 48, 1)'],
  ['rgba(255, 209, 48, 0)', 'rgba(255, 209, 48, 1)']
]
let data = ref({
  xdata: ['孙思邈', '赵xx', '李xx', '孙xx', '方xx'],
  ydata: [10, 8, 7, 7, 5]
})
let dataList = ref([
  { label: '孙思邈', value: 10 },
  { label: '赵xx', value: 8 },
  { label: '李xx', value: 7 },
  { label: '孙xx', value: 7 },
  { label: '方xx', value: 5 }
])
onMounted(() => {
  setEchart()
})
const setEchart = () => {
  if (myEchart != null && myEchart != '' && myEchart != undefined) {
    myEchart.dispose() //销毁
  }
  myEchart = echarts.init(barEchart.value, null, { renderer: 'svg' })
  let option = {
    tooltip: {
      trigger: 'axis',
      textStyle: {
        fontSize: 22 // 字体大小
      },
      axisPointer: {
        // Use axis to trigger tooltip
        type: 'shadow' // 'shadow' as default; can also be 'line' or 'shadow'
      }
    },
    grid: {
      left: '12%',
      right: '20%',
      bottom: '0%',
      top: '10%',
      containLabel: true
    },
    xAxis: {
      type: 'value',
      // max: 10,
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      splitLine: {
        //修改背景线条样式
        show: false
      },
      axisLabel: {
        show: false
      }
    },
    yAxis: {
      type: 'category',
      data: data.value.xdata.reverse(),
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisLabel: {
        show: false
      },
      splitLine: {
        //修改背景线条样式
        show: false
      }
    },
    series: [
      {
        type: 'bar',
        // label: {
        //   show: true,
        //   color: '#fff',
        //   fontSize: 18
        // },
        barWidth: 11,
        emphasis: {
          focus: 'series'
        },
        // showBackground: true, //开启背景
        // backgroundStyle: {
        //   //设置背景样式
        //   color: 'rgba(42, 53, 68, 1)',
        //   barBorderRadius: 10
        // },

        data: data.value.ydata.reverse(),
        itemStyle: {
          color: (param) => {
            return new echarts.graphic.LinearGradient(0, 0, 1, 0, [
              { offset: 0, color: colorList[param.dataIndex][0] },
              { offset: 1, color: colorList[param.dataIndex][1] }
            ])
          },
          borderRadius: [0, 20, 20, 0]
        }
      }
    ]
  }
  myEchart.setOption(option)
}
</script>
<style scoped lang="scss">
.status {
  margin-top: 24px;
  .bottom {
    position: relative;
    .barEchart {
      width: 500px;
      height: 360px;
    }
    .legend {
      top: 63px;
      left: 0;
      position: absolute;
      z-index: -1;
      .box {
        display: flex;
        align-items: center;
        width: 477.5px;
        height: 25px;
        box-sizing: border-box;
        background: url('@/assets/images/thirdpage/dizuo.png') no-repeat;
        background-size: 100% 100%;
        margin-bottom: 40px;
        .icon {
          display: inline-block;
          width: 29px;
          height: 26px;
          box-sizing: border-box;
          background: url('@/assets/images/thirdpage/yellow.png') no-repeat;
          background-size: 100% 100%;
          display: flex;
          justify-content: center;
          align-items: center;
          transform: translateY(-10px);
        }
        .label {
          font-size: 16px;
          font-family: pmzd;
          font-weight: 400;
          color: #ffffff;
          margin-left: 5px;
          transform: translateY(-10px);
        }
        .value {
          transform: translate(340px, -10px);
          font-size: 35px;
          font-family: pmzd;
          font-weight: 400;
          color: #ffd800;
          .unit {
            font-size: 15px;
            font-family: Microsoft YaHei;
            font-weight: 400;
            color: #ffffff;
          }
        }
        &:nth-child(4) {
          .icon {
            width: 30.5px;
            height: 28px;
            background: url('@/assets/images/thirdpage/blue.png') no-repeat;
            background-size: 100% 100%;
          }
        }
        &:nth-child(5) {
          margin-bottom: 40px;
        }
      }
    }
  }
}
</style>
